import Vue from 'vue'
import Vuex from 'vuex'
import menus from './modules/menus'
import userInfo from './modules/userInfo'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: localStorage.getItem("token"),
    index: {
      name: "Index",
      title: "首页",
      path: "/index",
      icon: "el-icon-s-home",
      component: "Index"
    }
  },
  mutations: {
    SET_TOKEN:(state, jwt) =>{
      state.token = jwt
      localStorage.setItem("token", jwt)
    },
    SET_ROLE:(state, role) =>{
      state.role = role
      localStorage.setItem("role", role)
    },
    resetState:(state)=>{
      state.token = ''
      state.role = ''
      localStorage.clear()
      userInfo.state.info = {}
      menus.state.hasRoute = false
      menus.state.menuList= []
      menus.state.permList= []
      menus.state.editableTabsValue= 'Index'
      menus.state.editableTabs= [
        {
        title: '首页',
        name: 'Index',
        },
      ]
    }
  },
  actions: {
  },
  modules: {
    menus,
    userInfo
  }
})
